﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Components;
using Model;


namespace MsDAL
{
   public partial  class Pot0b01Base
    {		
		/// <summary>
        /// 增加一条数据
        /// </summary>
        public virtual  SqlApp Add(Model.Pot0b01 pot0b01)
        {
			StringBuilder strSql = new StringBuilder();
			strSql.Append("insert into Pot0b01(");
			strSql.Append("frameid ,usercode ,tmp3 ,tmp1 ,tmp2 )");
			strSql.Append(" values (");
			strSql.Append("@frameid ,@usercode ,@tmp3 ,@tmp1 ,@tmp2 )");		

			SqlParameter[] parameters = {
				new SqlParameter("@frameid",SqlDbType.NVarChar),
				new SqlParameter("@usercode",SqlDbType.NVarChar),
				new SqlParameter("@tmp3",SqlDbType.NVarChar),
				new SqlParameter("@tmp1",SqlDbType.NVarChar),
				new SqlParameter("@tmp2",SqlDbType.NVarChar)
				};
			parameters[0].Value = pot0b01.Frameid;
			parameters[1].Value = pot0b01.Usercode;
			parameters[2].Value = pot0b01.Tmp3;
			parameters[3].Value = pot0b01.Tmp1;
			parameters[4].Value = pot0b01.Tmp2;
			
			return new SqlApp(strSql.ToString(),new ArrayList(parameters), false, "数据保存失败！");
        }
	
        /// <summary>
        /// 判断某个值是否存在表中的某个字段
        /// </summary>
        /// <param name="Condition">条件字段名 例:A=@A</param>
        /// <param name="hs">参数和值 如hs["@A"]=123</param>
        /// <returns></returns>
        public virtual bool Exists(String condition, Hashtable hs)
        {
			StringBuilder strSql = new StringBuilder();
			strSql.Append("select count(1) from Pot0b01 ");
			if (!string.IsNullOrEmpty(condition))
				strSql.Append(" where " + condition);
			List<SqlParameter> list = DBHelper.GetListByHashtable(hs);
			if (list.Count > 0)
				return Convert.ToInt32(DBHelper.ExecuteScalar(strSql.ToString(), list.ToArray())) > 0;
			else
				return Convert.ToInt32(DBHelper.ExecuteScalar(strSql.ToString())) > 0;
        }

		
		
		 /// <summary>
        /// 得到Sql语句
        /// </summary>
        /// <param name="Condition">Sql语句的条件</param>
		/// <param name="OrderBy">排序条件，默认为String.Empty</param>
        /// <returns></returns>
        protected virtual String GetSql(string condition,string orderBy)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [frameid] ,[usercode] ,[tmp3] ,[tmp1] ,[tmp2] ");
            strSql.Append(" FROM Pot0b01 ");
 			
			if (!string.IsNullOrEmpty(condition)) strSql.Append(" where " + condition);				
			if(!string.IsNullOrEmpty(orderBy)) strSql.Append( " order by " + orderBy );
			
            return  strSql.ToString();
        }

        /// <summary>
        /// 根据条件和参数得到Pot0b01对象
        /// </summary>
        /// <param name="Condition">Sql条件</param>
        /// <param name="hs">参数和值</param>
        /// <returns></returns>
        public virtual Model.Pot0b01 GetModel(String Condition, Hashtable hs)
        {
			String sql = GetSql(Condition,String.Empty);
			DataTable dt = DBHelper.GetTableByCondition(sql,  hs);
			return (dt.Rows.Count > 0) ? Model.Pot0b01.GetPot0b01ListByDataTable(dt)[0] : null;
        }

		
		public virtual DataTable GetList(string c,Hashtable hs)
		{
			string sql = GetSql(c,null); //得到SQL语句
			//返回结果集
			return DBHelper.GetData(sql,DBHelper.GetListByHashtable(hs).ToArray());
		}
    }
}
